package com.team2.s3hrjyxm.qxglcontroller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.team2.s3hrjyxm.QxglService.RoleService;
import com.team2.s3hrjyxm.pojo.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;

@Controller
public class RoleController {
    @Autowired
    RoleService service;

    @RequestMapping("right_list")
       public String rightquery(Map map,
        @RequestParam(defaultValue = "1",required = false) Integer startPage,
        @RequestParam(defaultValue = "5",required = false) Integer PageSize){

        PageHelper.startPage(startPage, PageSize );//使用分页插件
        List<Role> list= service.RoleQuery();
        PageInfo pageInfo=new PageInfo(list, 5); //保存分页信息
        map.put("items", list);
        map.put("pageInfo", pageInfo); //绑定分页信息
        return "page/power/right_list.html";
    }
        @RequestMapping("right_add")
         public String  rightadd(){

            return "page/power/right_add.html";
       }
        @RequestMapping("roleadd")
         public String  rightadd2(Role r){
                  service.roleadd(r);
           return "page/power/successrole.html";
    }


           @RequestMapping("role_update1")
       public String  roleupdate1(int role_Id,Map map){
            Role role= service.RoleQuerybyid(role_Id);
                map.put("r", role);
        return "page/power/right_list_information.html";
    }
          @RequestMapping("role_update2")
        public String  roleupdate2(Role role){
            service.roleupdate(role);

        return "page/power/successrole.html";
    }

          @RequestMapping("role_delete")
         public String roledelete(int role_Id){
               service.roledelete(role_Id);
            return "page/power/successrole.html";
    }
}
